package com.wiloon.java.network.network.nettyhttpserver.monitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Roy on 2015/11/4;
 */
public class AvgValue {
    private final static Logger logger = LoggerFactory.getLogger(AvgValue.class);
    private double total;
    private int count;
    private double avg;

    public double calculate(double num) {
        double tmpAvg = 0;
        if (Double.isNaN(num)) num = 0;

        total += num;
        count += 1;
        tmpAvg = total / count;

        logger.trace("param={},total={},count={},avg={}", num, total, count, tmpAvg);
        if (!Double.isNaN(tmpAvg)) avg = tmpAvg;
        return Math.floor(avg);
    }
}
